$(function () {
    obj.init();
});

var obj = new function () {
    return {
        dataGrid: null,
        dom: {
            save: null
        },
        params: {
            id: null
        },
        init: function () {
            this.params.id = xhTool.getQuery('id');

            this.dom.save = window.top.xhTop.getModalConfirmDom();

            this.dataGrid = new xhDataGrid($('#list'), 'Ask/getQuestion');
            this.dataGrid.init().activeBtn(this.dom.save, null, 'bs');

            this.listener();
        },
        listener: function () {
            var $this = this;
            //保存
            $this.dom.save.click(function () {
                 $this.funObj().saveQuestion();
            });
        },
        funObj: function () {
            var $this = this;
            return {
                saveQuestion: function () {
                    var ids = $this.dataGrid.getSelectValues('iAQId');
                    if (!ids) {
                        window.top.xhTop.showError('未选中题目');
                        xhExtra.setBtnNormal($this.dom.save);
                        return false;
                    }
                    xhExtra.ajaxRequest('Ask/setSurveyQuestion', {id: $this.params.id, queIds: ids}, {check: true, success: true}, function () {
                        xhExtra.setBtnNormal($this.dom.save);
                        window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        window.top.xhTop.closeModal();
                    });
                }
            }
        }
    }
};